﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Absky.Web.Operator;
using Absky.Model;
using Absky.Enum;
using Absky.Entity.SystemManage;
using Absky.Business.SystemManage;
using Absky.Util;

namespace Absky.Web.Controllers
{
    public class HomeController : BaseController
    {
        private readonly MenuBLL menuBLL = new MenuBLL();
        private readonly MenuAuthorizeBLL menuAuthorizeBLL = new MenuAuthorizeBLL();

        #region 视图功能
        [HttpGet]
        [AuthorizeOnly]
        public async Task<IActionResult> Index()
        {
            OperatorInfo operatorInfo = await Operator.Operator.Instance.Current();

            Result<List<MenuEntity>> objMenu = await menuBLL.GetList(null);
            List<MenuEntity> menuList = objMenu.Data;
            menuList = menuList.Where(p => p.MenuStatus == StatusEnum.Yes.ParseToInt()).ToList();

            if (operatorInfo.IsSystem != 1)
            {
                Result<List<MenuAuthorizeInfo>> objMenuAuthorize = await menuAuthorizeBLL.GetAuthorizeList(operatorInfo);
                List<long?> authorizeMenuIdList = objMenuAuthorize.Data.Select(p => p.MenuId).ToList();
                menuList = menuList.Where(p => authorizeMenuIdList.Contains(p.Id)).ToList();
            }

            ViewBag.MenuList = menuList;
            ViewBag.OperatorInfo = operatorInfo;

            string absky_UItheme = CookieHelper.GetCookie("Absky_UItheme");
            switch (absky_UItheme)
            {
                case "1":
                    return View("AdminTheme1");      // 主题1
                case "2":
                    return View("AdminTheme2");    // 主题2
                case "3":
                    return View("AdminTheme3");       // 主题3
                case "4":
                    return View("AdminTheme4");          // 主题4
                case "5":
                    return View("AdminTheme5");            // 主题5
                default:
                    return View("AdminTheme5");            // 默认主题
            }
        }
        /// <summary>
        /// 首页桌面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult AdminDesktop()
        {
            string absky_UItheme = CookieHelper.GetCookie("Absky_UItheme");
            switch (absky_UItheme)
            {
                case "1":
                    return View("AdminDesktop1");      // 经典版本
                case "2":
                    return View("AdminDesktop2");    // 手风琴版本
                case "3":
                    return View("AdminDesktop3");       // Windos版本
                case "4":
                    return View("AdminDesktop4");          // 顶部菜单版本
                case "5":
                    return View("AdminDesktop5");      // 主题五
                default:
                    return View("AdminDesktop5");      // 经典版本
            }
        }
        /// <summary>
        /// 首页模板
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult AdminDesktopTemp()
        {
            return View();
        }

        /// <summary>
        /// 首页模板
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult DesktopIndex()
        {
            return View();
        }

        [HttpGet]
        public IActionResult Welcome()
        {
            return View();
        }

        [HttpGet]
        public IActionResult Skin()
        {
            return View();
        }
        #endregion
    }
}
